/*
 * Created by JFormDesigner on Thu Apr 14 19:51:01 CST 2022
 */

package com.ZengQi.event.view;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author QI Zeng
 */

/**
 * 用户的主界面
 */
public class UserMainView extends JFrame {
    private String userName;
    public UserMainView(String userName) {
        this.userName=userName;
        initComponents();
        userNameTxt.setText(userName);
        setVisible(true);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    private void logoutBtn(ActionEvent e) {
        logoutBtnActionPerformed(e);
    }

    private void logoutBtnActionPerformed(ActionEvent e) {
        dispose();
        new VisitorsMainView();

    }

    private void companyBtn(ActionEvent e) {
        companyBtnActionPerformed(e);
    }

    private void companyBtnActionPerformed(ActionEvent e) {
        new CompanyView();
    }

    private void lookUserBtn(ActionEvent e) {
        lookUserBtnActionPerformed(e);
    }

    private void lookUserBtnActionPerformed(ActionEvent e) {
        new LookUserInformationView(userName);
    }

    private void searchBtn(ActionEvent e) {
        searchBtnActionPerformed(e);
    }

    private void searchBtnActionPerformed(ActionEvent e) {
        new UserSearchView(this);
    }

    public JTextField getSearchTxt() {
        return searchTxt;
    }

    public JTextField getUserNameTxt() {
        return userNameTxt;
    }

    private void updateUserBtn(ActionEvent e) {
        updateBtnActionPerformed(e);
    }

    private void updateBtnActionPerformed(ActionEvent e) {
        new UpdateUserInformationView(userName);
    }

    private void finishBtn(ActionEvent e) {
        finishBtnActionPerformed(e);
    }

    private void finishBtnActionPerformed(ActionEvent e) {
            new UserFinishedView(userName);
    }

    /**
     * 组件布局及初始化
     */
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        panel1 = new JPanel();
        welcomeLabel = new JLabel();
        userNameTxt = new JTextField();
        companyBtn = new JButton();
        lookUserBtn = new JButton();
        updateUserBtn = new JButton();
        finishBtn = new JButton();
        label1 = new JLabel();
        searchTxt = new JTextField();
        searchBtn = new JButton();
        logoutBtn = new JButton();

        //======== this ========
        setTitle("\u505a\u9898\u5e2e");
        setIconImage(new ImageIcon(getClass().getResource("/bang.png")).getImage());
        Container contentPane = getContentPane();

        //======== panel1 ========
        {

            //---- welcomeLabel ----
            welcomeLabel.setText("\u6b22\u8fce\u60a8");

            //---- userNameTxt ----
            userNameTxt.setEditable(false);

            //---- companyBtn ----
            companyBtn.setText("\u4f01\u4e1a\u4fe1\u606f");
            companyBtn.addActionListener(e -> companyBtn(e));

            //---- lookUserBtn ----
            lookUserBtn.setText("\u67e5\u770b\u4e2a\u4eba\u4fe1\u606f");
            lookUserBtn.addActionListener(e -> lookUserBtn(e));

            //---- updateUserBtn ----
            updateUserBtn.setText("\u4fee\u6539\u4e2a\u4eba\u4fe1\u606f");
            updateUserBtn.addActionListener(e -> updateUserBtn(e));

            //---- finishBtn ----
            finishBtn.setText("\u5386\u53f2\u8bb0\u5f55");
            finishBtn.addActionListener(e -> finishBtn(e));

            //---- label1 ----
            label1.setText("\u8bf7\u8f93\u5165\u67e5\u627e\u9898\u76ee");

            //---- searchBtn ----
            searchBtn.setText("\u627e\u9898");
            searchBtn.addActionListener(e -> searchBtn(e));

            //---- logoutBtn ----
            logoutBtn.setText("\u9000\u51fa\u767b\u5f55");
            logoutBtn.addActionListener(e -> logoutBtn(e));

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGroup(panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(174, 174, 174)
                                .addComponent(welcomeLabel, GroupLayout.PREFERRED_SIZE, 59, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, 236, GroupLayout.PREFERRED_SIZE))
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(33, 33, 33)
                                .addComponent(label1, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(searchTxt, GroupLayout.PREFERRED_SIZE, 218, GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(searchBtn)))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 106, Short.MAX_VALUE)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                            .addComponent(companyBtn, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
                            .addComponent(lookUserBtn, GroupLayout.Alignment.LEADING)
                            .addComponent(updateUserBtn, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(141, 141, 141))
                    .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                        .addGap(140, 140, 140)
                        .addComponent(logoutBtn, GroupLayout.PREFERRED_SIZE, 207, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 248, Short.MAX_VALUE)
                        .addComponent(finishBtn, GroupLayout.PREFERRED_SIZE, 152, GroupLayout.PREFERRED_SIZE)
                        .addGap(131, 131, 131))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGroup(panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(welcomeLabel, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(56, 56, 56)
                                .addComponent(companyBtn, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)))
                        .addGap(30, 30, 30)
                        .addGroup(panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(lookUserBtn, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
                                .addComponent(label1, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE))
                            .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(searchTxt, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
                                .addComponent(searchBtn)))
                        .addGap(18, 18, 18)
                        .addComponent(updateUserBtn)
                        .addGap(33, 33, 33)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(finishBtn, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
                            .addComponent(logoutBtn, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(196, Short.MAX_VALUE))
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addComponent(panel1, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JLabel welcomeLabel;
    private JTextField userNameTxt;
    private JButton companyBtn;
    private JButton lookUserBtn;
    private JButton updateUserBtn;
    private JButton finishBtn;
    private JLabel label1;
    private JTextField searchTxt;
    private JButton searchBtn;
    private JButton logoutBtn;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
